<?php

namespace app\admin\model\finance;

use think\Model;
use app\admin\library\Auth;

class FinanceLog extends Model
{

    

    

    // 表名
    protected $name = 'finance_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    







    public function order()
    {
        return $this->belongsTo('app\admin\model\Order', 'oid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function personal()
    {
        return $this->belongsTo('app\admin\model\personal\Personal', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * 添加财务记录
     */
    public function addFinanceLog($uid,$title,$before_balance,$before_jybalance, $money, $balance,$jy_balance, $content)
    {
        $auth = Auth::instance();
        $data = [
            'uid'               => $uid,
            'title'             => $title,
            'before_balance'    => $before_balance,
            'before_jybalance'  => $before_jybalance,
            'money'             => $money,
            'balance'           => $balance,
            'jy_balance'        => $jy_balance,
            'content'           => $content,
            'createtime'        => time(),
            'admin_id'          => $auth->isLogin() ? $auth-> id: 0,
            'admin'             => $auth->isLogin() ? $auth-> username: 0,
        ];
        $result = self::allowField(true)->save($data);
        return $result;
    }
}
